package com.zjc.yohoshop.mvp.view.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.zjc.lib_core.base.BaseFragment;
import com.zjc.yohoshop.R;
import com.zjc.yohoshop.bean.SeeCategoryEntity;
import com.zjc.yohoshop.di.compont.DaggerSeeFragmentCompont;
import com.zjc.yohoshop.di.modules.SeeFragmentModules;
import com.zjc.yohoshop.mvp.contract.SeeFragmentContract;
import com.zjc.yohoshop.mvp.persenter.SeeFragmentPresenter;
import com.zjc.yohoshop.mvp.view.adapter.SeeViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 逛页面
 */
public class SeeFragment extends BaseFragment<SeeFragmentPresenter> implements SeeFragmentContract.SeeFragmentIView {
    private TabLayout tl_see;
    private ViewPager vp_see;
    private List<Fragment> fragments = new ArrayList<>();
    private List<String> list = new ArrayList<>();
    private SeeViewPagerAdapter adapter;

    @Override
    public View createView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_see, null);
        return view;
    }

    @Override
    public void init(View view) {
        tl_see = view.findViewById(R.id.tl_see);
        vp_see = view.findViewById(R.id.vp_see);

    }

    @Override
    public void initData() {
        p.request();
    }

    @Override
    public void setupDagger() {
        DaggerSeeFragmentCompont.builder().seeFragmentModules(new SeeFragmentModules(this))
                .build().inject(this);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void success(SeeCategoryEntity entity) {

        for (SeeCategoryEntity.ValuesBean valuesBean : entity.values){
            list.add(valuesBean.see_category_name);
        }
        fragments.add(new SeeListFragment());
        for (int i = 0; i < list.size() - 1; i++){
            fragments.add(new SeeListElseFragment());
        }

        adapter = new SeeViewPagerAdapter(getActivity().getSupportFragmentManager(), fragments, list);
        vp_see.setAdapter(adapter);
        //设置TabLayout的模式
        tl_see.setTabMode(TabLayout.MODE_FIXED);
        //让tablayout和Viewpager关联;
        tl_see.setupWithViewPager(vp_see);
    }

    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }


}
